class Solution {
public:
    vector<vector<int>> generate(int numRows) {
     vector<vector<int>> ret(numRows); // Initialize ret with numRows empty vectors
        for (int i = 0; i < numRows; i++) {
            ret[i].resize(i + 1); // Resize the current row to have i + 1 elements
            ret[i][0] = 1; // The first element is always 1
            ret[i][i] = 1; // The last element is always 1
            
            // Fill in the values for the current row
            if (i >= 2) {
                for (int left = 1; left < i; left++) {
                    //对于杨辉三角中某一行中间的值等于上一行这个位置的值和上一行这个位置左边的值的和
                    ret[i][left] = ret[i - 1][left] + ret[i - 1][left - 1];
                }
            }
        }
        return ret; // Return the completed triangle
    }
};